local card_extension = Package:new("zhonger_heg_cards", Package.CardPack)
card_extension.extensionName = "sifu_heg"

local extension = Package:new("zhonger_heg_generals")
extension.extensionName = "sifu_heg"

extension.game_modes_whitelist = {"zhonger_heg_mode"}
card_extension.game_modes_whitelist = {"zhonger_heg_mode"}

Fk:loadTranslationTable{
  ["zhonger_heg_cards"] = "国标+势备",
  ["zhonger_heg_generals"] = "国战标准",
  ["zhonger_st_heg"] = "国标"
}

local H = require "packages/ol_hegemony/util"
local U = require "packages/utility/utility"

local standard_cards = require "packages/ol_hegemony/hegemony_cards"
local strategic_advantage = require "packages/ol_hegemony/strategic_advantage"



local card_packs = {standard_cards , strategic_advantage}

local ban_cards = {"double_swords", "jingfan","six_swords", "zhuahuangfeidian"}

for _, extension in ipairs(card_packs) do
  for _, card in ipairs(extension.cards) do
    if not table.contains(ban_cards, card.name) then
      local c = Fk:cloneCard(card.name, card.suit, card.number)
      card_extension:addCard(c)
      if table.contains(H.allianceCards, card) then
        table.insert(H.allianceCards, c)
      end
    end
  end
end


local caocao = General(extension, "zhonger_st_heg__caocao", "wei", 4, 4,  General.Male)

caocao:addSkill("jianxiong")
caocao:addCompanions({"zhonger_st_heg__dianwei", "zhonger_st_heg__xuchu"})
Fk:loadTranslationTable{
  ["zhonger_st_heg__caocao"] = "曹操",
  ["#zhonger_st_heg__caocao"] = "魏武帝",
  ["illustrator:zhonger_st_heg__caocao"] = "KayaK",
  ["~zhonger_st_heg__caocao"] = "霸业未成，未成啊……",
}

local simayi = General(extension, "zhonger_st_heg__simayi", "wei", 3, 3,  General.Male)
simayi:addSkill("fankui")
simayi:addSkill("ex__guicai") -- 手杀
Fk:loadTranslationTable{
  ["zhonger_st_heg__simayi"] = "司马懿",
  ["#zhonger_st_heg__simayi"] = "狼顾之鬼",
  ["illustrator:zhonger_st_heg__simayi"] = "木美人",
  ["~zhonger_st_heg__simayi"] = "我的气数就到这里了吗？",
}

local xiahoudun = General(extension, "zhonger_st_heg__xiahoudun", "wei", 4, 4,  General.Male)
xiahoudun:addSkill("ex__ganglie")
xiahoudun:addCompanions("zhonger_st_heg__xiahouyuan")
Fk:loadTranslationTable{
  ["zhonger_st_heg__xiahoudun"] = "夏侯惇",
  ["#zhonger_st_heg__xiahoudun"] = "独眼的罗刹",
  ["illustrator:zhonger_st_heg__xiahoudun"] = "DH",
  ["~zhonger_st_heg__xiahoudun"] = "诸多败绩，有负丞相重托……",
}

local zhangliao = General(extension, "zhonger_st_heg__zhangliao", "wei", 4, 4,  General.Male)
zhangliao:addSkill("ex__tuxi") -- 手杀
Fk:loadTranslationTable{
  ["zhonger_st_heg__zhangliao"] = "张辽",
  ["#zhangliao"] = "前将军",
  ["illustrator:zhangliao"] = "张帅",
  ["~zhonger_st_heg__zhangliao"] = "被敌人占了先机……呃……",
}

local xuchu = General(extension, "zhonger_st_heg__xuchu", "wei", 4, 4,  General.Male)
local zhonger_st_heg__luoyi = fk.CreateTriggerSkill{
  name = "zhonger_st_heg__luoyi",
  anim_type = "offensive",
  events = {fk.EventPhaseEnd},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.phase == Player.Draw
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player.room:askForDiscard(player, 1, 1, false, self.name, false, nil, "zhonger_st_heg__luoyi-ask", false)
    room:addPlayerMark(player,"@@heg_luoyi-turn",1)
  end,
}
local zhonger_st_heg__luoyi_trigger = fk.CreateTriggerSkill{
  name = "#zhonger_st_heg__luoyi_trigger",
  mute = true,
  events = {fk.DamageCaused},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:usedSkillTimes("zhonger_st_heg__luoyi", Player.HistoryTurn) > 0 and
      not data.chain and data.card and (data.card.trueName == "slash" or data.card.name == "duel")
  end,
  on_cost = function(self, event, target, player, data)
    return true
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:broadcastSkillInvoke("zhonger_st_heg__luoyi")
    room:notifySkillInvoked(player, "zhonger_st_heg__luoyi")
    data.damage = data.damage + 1
  end,
}

zhonger_st_heg__luoyi:addRelatedSkill(zhonger_st_heg__luoyi_trigger)
xuchu:addSkill(zhonger_st_heg__luoyi)
Fk:loadTranslationTable{
  ["zhonger_st_heg__xuchu"] = "许褚",
  ["#xuchu"] = "虎痴",
  ["illustrator:xuchu"] = "KayaK",
  ["zhonger_st_heg__luoyi"]="裸衣",
  ["@@heg_luoyi-turn"]="裸衣",
  ["zhonger_st_heg__luoyi-ask"]="你可以弃置一张牌，于此回合内执行【杀】或【决斗】的效果造成伤害时伤害+1",
  [":zhonger_st_heg__luoyi"]="摸牌阶段结束时，你可弃置一张牌，令你于此回合内执行【杀】或【决斗】的效果造成伤害时，此伤害+1。",
  ["$zhonger_st_heg__luoyi1"] = "脱！",
  ["$zhonger_st_heg__luoyi2"] = "谁来与我大战三百回合？",
  ["~zhonger_st_heg__xuchu"] = "冷，好冷啊……",
}

local guojia = General(extension, "zhonger_st_heg__guojia", "wei", 3, 3,  General.Male)
local hs__yiji_active = fk.CreateActiveSkill{
  name = "hs__yiji_active",
  expand_pile = function(self)
    return Self:getTableMark("hs__yiji_cards")
  end,
  min_card_num = 1,
  target_num = 1,
  card_filter = function(self, to_select, selected, targets)
    local ids = Self:getMark("hs__yiji_cards")
      return type(ids) == "table" and table.contains(ids, to_select)
  end,
  target_filter = function(self, to_select, selected, selected_cards)
    return #selected == 0 and to_select ~= Self.id
  end,
}
Fk:addSkill(hs__yiji_active)
local yiji = fk.CreateTriggerSkill{
  name = "hs__yiji",
  anim_type = "masochism",
  events = {fk.Damaged},
  on_use = function(self, event, target, player, data)
    local room = player.room
    local ids = room:getNCards(2)
    while true do
      room:setPlayerMark(player, "hs__yiji_cards", ids)
      local _, ret = room:askForUseActiveSkill(player, "hs__yiji_active", "#hs__yiji-give", true, nil, true)
      room:setPlayerMark(player, "hs__yiji_cards", 0)
      if ret then
        for _, id in ipairs(ret.cards) do
          table.removeOne(ids, id)
        end
        room:moveCardTo(ret.cards, Card.PlayerHand, room:getPlayerById(ret.targets[1]), fk.ReasonGive, self.name, nil, false, player.id)
        if #ids == 0 then break end
        if player.dead then
          room:moveCards({
            ids = ids,
            toArea = Card.DiscardPile,
            moveReason = fk.ReasonJustMove,
            skillName = self.name,
          })
          break
        end
      else
        room:moveCardTo(ids, Player.Hand, player, fk.ReasonGive, self.name, nil, false, player.id)
        break
      end
    end
  end,
}
guojia:addSkill(yiji)
guojia:addSkill("tiandu")
Fk:loadTranslationTable{
  ["zhonger_st_heg__guojia"] = "郭嘉",
  ["#zhonger_st_heg__guojia"] = "早终的先知",
  ["illustrator:zhonger_st_heg__guojia"] = "绘聚艺堂",

  ["hs__yiji"] = "遗计",
  [":hs__yiji"] = "当你受到伤害后，你可观看牌堆顶的两张牌并分配。",

  ["#hs__yiji-give"] = "遗计：你可以将这些牌分配给其他角色，或点“取消”自己保留",
  ["hs__yiji_active"] = "遗计",

  ["$hs__yiji1"] = "也好。",
  ["$hs__yiji2"] = "罢了。",
  ["~zhonger_st_heg__guojia"] = "咳，咳……",
}

local zhenji = General(extension, "zhonger_st_heg__zhenji", "wei", 3, 3, General.Female)
zhenji:addSkill("hs__luoshen")
zhenji:addSkill("hs__qingguo")
zhenji:addCompanions("zhonger_st_heg__caopi")

Fk:loadTranslationTable{
  ["zhonger_st_heg__zhenji"] = "甄姬",
  ["#zhonger_st_heg__zhenji"] = "薄幸的美人",
  ["illustrator:zhonger_st_heg__zhenji"] = "DH",
  ["~zhonger_st_heg__zhenji"] = "悼良会之永绝兮，哀一逝而异乡。",
}

local xiahouyuan = General(extension, "zhonger_st_heg__xiahouyuan", "wei", 5 ,5, General.Male)
xiahouyuan:addSkill("hs__shensu")
Fk:loadTranslationTable{
  ["zhonger_st_heg__xiahouyuan"] = "夏侯渊",
  ["#zhonger_st_heg__xiahouyuan"] = "疾行的猎豹",
  ["illustrator:zhonger_st_heg__xiahouyuan"] = "凡果",
  ["~zhonger_st_heg__xiahouyuan"] = "我的速度…还是不够……",
}

local zhanghe = General(extension, "zhonger_st_heg__zhanghe", "wei", 4, 4,  General.Male)
zhanghe:addSkill("qiaobian")
Fk:loadTranslationTable{
  ["zhonger_st_heg__zhanghe"] = "张郃",
  ["#zhonger_st_heg__zhanghe"] = "料敌机先",
  ["illustrator:zhonger_st_heg__zhanghe"] = "张帅",
  ["~zhonger_st_heg__zhanghe"] = "呃，膝盖中箭了……",
}

local xuhuang = General(extension, "zhonger_st_heg__xuhuang", "wei", 4, 4,  General.Male)
local duanliang = fk.CreateViewAsSkill{
  name = "hs__duanliang",
  anim_type = "control",
  pattern = "supply_shortage",
  expand_pile = "$carriage&",
  card_filter = function(self, to_select, selected)
    if Self:getPileNameOfId(to_select)  == "$carriage&" or Fk:getCardById(to_select)  then
      return #selected == 0 and Fk:getCardById(to_select).color == Card.Black and Fk:getCardById(to_select).type ~= Card.TypeTrick
    end
      end,
  view_as = function(self, cards)
    if #cards ~= 1 then
      return nil
    end
    local c = Fk:cloneCard("supply_shortage")
    c.skillName = self.name
    c:addSubcard(cards[1])
    return c
  end,
  before_use = function(self, player, use)
    local targets = TargetGroup:getRealTargets(use.tos)
    if #targets == 0 then return end
    local room = player.room
    for _, p in ipairs(targets) do
      if player:distanceTo(room:getPlayerById(p)) > 2 then
        room:invalidateSkill(player, self.name, "-phase")
        room:setPlayerMark(player, "@@hs__duanliang-phase", 1)
      end
    end
  end
}
local duanliang_targetmod = fk.CreateTargetModSkill{
  name = "#hs__duanliang_targetmod",
  bypass_distances = function (self, player, skill, card, to)
    return player:hasSkill(duanliang) and skill.trueName == "supply_shortage_skill" and player:distanceTo(to) > 2
  end
}
duanliang:addRelatedSkill(duanliang_targetmod)
xuhuang:addSkill(duanliang)

Fk:loadTranslationTable{
  ["zhonger_st_heg__xuhuang"] = "徐晃",
  ["#zhonger_st_heg__xuhuang"] = "周亚夫之风",
  ["illustrator:zhonger_st_heg__xuhuang"] = "Tuu.",

  ["hs__duanliang"] = "断粮",
  [":hs__duanliang"] = "你可将一张不为锦囊牌的黑色牌当【兵粮寸断】使用（无距离关系的限制），若你至目标对应的角色的距离大于2，此技能于此阶段内无效。",

  ["@@hs__duanliang-phase"] = "断粮 无效",

  ["$hs__duanliang1"] = "截其源，断其粮，贼可擒也。",
  ["$hs__duanliang2"] = "人是铁，饭是钢。",
  ["~zhonger_st_heg__xuhuang"] = "敌军防备周全，是吾轻敌......",
}

local caoren = General(extension, "zhonger_st_heg__caoren", "wei", 4, 4,  General.Male)
caoren:addSkill("hs__jushou")
Fk:loadTranslationTable{
  ["zhonger_st_heg__caoren"] = "曹仁",
  ["#zhonger_st_heg__caoren"] = "大将军",
  ["illustrator:zhonger_st_heg__caoren"] = "Ccat",
  ["~zhonger_st_heg__caoren"] = "实在是守不住了……",
}

local dianwei = General(extension, "zhonger_st_heg__dianwei", "wei", 4,4,General.Male)
local hs__qiangxi = fk.CreateActiveSkill{
  name = "hs__qiangxi",
  anim_type = "offensive",
  max_card_num = 1,
  target_num = 1,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  card_filter = function(self, to_select, selected)
    return Fk:getCardById(to_select).sub_type == Card.SubtypeWeapon
  end,
  target_filter = function(self, to_select, selected, selected_cards)
    return #selected == 0 and to_select ~= Self.id
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    if #effect.cards > 0 then
      room:throwCard(effect.cards, self.name, player)
    else
      room:loseHp(player, 1, self.name)
    end
    room:damage{
      from = player,
      to = target,
      damage = 1,
      skillName = self.name,
    }
  end,
}

dianwei:addSkill(hs__qiangxi)
Fk:loadTranslationTable{
  ['zhonger_st_heg__dianwei'] = '典韦',
  ["#zhonger_st_heg__dianwei"] = "古之恶来",
  ["illustrator:zhonger_st_heg__dianwei"] = "小冷",
  ["hs__qiangxi"] = "强袭",
  [":hs__qiangxi"] = "出牌阶段限一次，你可以失去1点体力或弃置一张武器牌，并选择一名其他角色，对其造成1点伤害。",

  ["$hs__qiangxi1"] = "吃我一戟！",
  ["$hs__qiangxi2"] = "看我三步之内取你小命！",
  ["~zhonger_st_heg__dianwei"] = "主公，快走！",
}

local xunyu = General(extension, "zhonger_st_heg__xunyu", "wei", 3, 3,  General.Male)
xunyu:addSkill("quhu")
xunyu:addSkill("jieming")
Fk:loadTranslationTable{
  ['zhonger_st_heg__xunyu'] = '荀彧',
  ["#zhonger_st_heg__xunyu"] = "王佐之才",
  ["illustrator:zhonger_st_heg__xunyu"] = "LiuHeng",
  ["~zhonger_st_heg__xunyu"] = "主公要臣死，臣不得不死。",
}

local caopi = General(extension, "zhonger_st_heg__caopi", "wei", 3, 3,  General.Male)
caopi:addSkill("xingshang")
caopi:addSkill("m_ex__fangzhu")
Fk:loadTranslationTable{
  ['zhonger_st_heg__caopi'] = '曹丕',
  ["#zhonger_st_heg__caopi"] = "霸业的继承者",
  ["illustrator:zhonger_st_heg__caopi"] = "DH",
  ["$m_ex__fangzhu_zhonger_st_heg__caopi1"] = "死罪可免，活罪难赦！",
  ["$m_ex__fangzhu_zhonger_st_heg__caopi2"] = "给我翻过来！",
  ["~zhonger_st_heg__caopi"] = "子建，子建……",
}

local yuejin = General(extension, "zhonger_st_heg__yuejin", "wei", 4, 4,  General.Male)
yuejin:addSkill("xiaoguo")
Fk:loadTranslationTable{
  ["zhonger_st_heg__yuejin"] = "乐进",
  ["#zhonger_st_heg__yuejin"] = "奋强突固",
  ["illustrator:zhonger_st_heg__yuejin"] = "巴萨小马",
  ["desinger:zhonger_st_heg__yuejin"] = "淬毒",
  ["~zhonger_st_heg__yuejin"] = "箭疮发作，吾命休矣。",
}

local liubei = General(extension, "zhonger_st_heg__liubei", "shu", 4, 4,  General.Male)
liubei:addSkill("ex__rende")
liubei:addCompanions({"zhonger_st_heg__guanyu", "zhonger_st_heg__zhangfei", "zhonger_st_heg__ganfuren"})
Fk:loadTranslationTable{
  ["zhonger_st_heg__liubei"] = "刘备",
  ["#zhonger_st_heg__liubei"] = "乱世的枭雄",
  ["illustrator:zhonger_st_heg__liubei"] = "木美人",
  ["~zhonger_st_heg__liubei"] = "汉室未兴，祖宗未耀，朕实不忍此时西去……",
}

local guanyu = General(extension, "zhonger_st_heg__guanyu", "shu", 5)
local ex__wusheng = fk.CreateViewAsSkill{
  name = "hs__wusheng",
  anim_type = "offensive",
  pattern = "slash",
  prompt = "#hs__wusheng",
  expand_pile = "$carriage&",
  card_filter = function(self, to_select, selected)
    if #selected == 1 then return false end
    if(H.getHegLord(Fk:currentRoom(), Self) and H.getHegLord(Fk:currentRoom(), Self):hasSkill("shouyue")) and Fk:getCardById(to_select) then
      return true
    end
    if Fk:getCardById(to_select).color == Card.Red then return true end
    if (Self:getPileNameOfId(to_select) == "$carriage&") then
      return Fk:getCardById(to_select).color == Card.Red
    end
  end,
  view_as = function(self, cards)
    if #cards ~= 1 then return nil end
    local c = Fk:cloneCard("slash")
    c.skillName = self.name
    c:addSubcard(cards[1])
    return c
  end,
}
local wusheng_targetmod = fk.CreateTargetModSkill{
  name = "#hswusheng_targetmod",
  anim_type = "offensive",
  bypass_distances = function (self, player, skill, card)
    return card and player:hasSkill(ex__wusheng) and skill.trueName == "slash_skill" and card.suit == Card.Diamond
  end
}
ex__wusheng:addRelatedSkill(wusheng_targetmod)
guanyu:addSkill(ex__wusheng)
Fk:loadTranslationTable{
  ["zhonger_st_heg__guanyu"] = "关羽",
  ["#zhonger_st_heg__guanyu"] = "威震华夏",
  ["illustrator:zhonger_st_heg__guanyu"] = "凡果",
  ["hs__wusheng"] = "武圣",
  [":hs__wusheng"] = "①你可以将一张红色牌当做【杀】使用或打出。②你使用<font color='red'>♦</font>【杀】无距离限制。",
  ["#hs__wusheng"] = "武圣：你可以将红色牌当【杀】使用或打出",
  ["$hs__wusheng1"] = "刀锋所向，战无不克！",
  ["$hs__wusheng2"] = "逆贼，哪里走！",
  ["~zhonger_st_heg__guanyu"] = "什么？此地名叫麦城？",
}

local zhangfei = General(extension, "zhonger_st_heg__zhangfei", "shu", 4, 4,  General.Male)
zhangfei:addSkill("hs__paoxiao")

Fk:loadTranslationTable{
  ["zhonger_st_heg__zhangfei"] = "张飞",
  ["#zhonger_st_heg__zhangfei"] = "万夫不当",
  -- ["illustrator:zhonger_st_heg__zhangfei"] = "宋其金",
  ["~zhonger_st_heg__zhangfei"] = "实在是杀不动了……",
}

local zhugeliang = General(extension, "zhonger_st_heg__zhugeliang", "shu", 3, 3,  General.Male)
zhugeliang:addSkill("hs__guanxing")
local kongcheng = fk.CreateTriggerSkill{
  name = "emptycity",
  anim_type = "defensive",
  events = {fk.TargetConfirming, fk.BeforeCardsMove, fk.EventPhaseStart},
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(self) then return false end
    if event == fk.EventPhaseStart then
      return player == target and player.phase == Player.Draw and #player:getPile("empty") > 0
    else
      if event == fk.TargetConfirming then
        if not player:isKongcheng() then return false end
        return target == player and (data.card.trueName == "slash" or data.card.name == "duel")
      elseif event == fk.BeforeCardsMove then
        if player.phase ~= Player.NotActive then return false end
        for _, move in ipairs(data) do
          if move.moveReason == fk.ReasonGive and move.to == player.id and move.toArea == Card.PlayerHand then
            return true
          end
        end
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.TargetConfirming then
      AimGroup:cancelTarget(data, player.id)
      return true
    elseif event == fk.BeforeCardsMove then
      local mirror_moves = {}
      for _, move in ipairs(data) do
        if move.moveReason == fk.ReasonGive and move.to == player.id and move.toArea == Card.PlayerHand then
          local mirror_info = move.moveInfo
          if #mirror_info > 0 then
            move.moveInfo = {}
            local mirror_move = table.clone(move)
            mirror_move.toArea = Card.PlayerSpecial
            mirror_move.specialName = "empty"
            mirror_move.visible = true
            mirror_move.moveMark = nil
            mirror_move.moveInfo = mirror_info
            table.insert(mirror_moves, mirror_move)
          end
        end
      end
      table.insertTable(data, mirror_moves)
    else
      room:obtainCard(player, player:getPile("empty"), true)
    end
  end
}
zhugeliang:addSkill(kongcheng)
zhugeliang:addCompanions("zhonger_st_heg__huangyueying")
Fk:loadTranslationTable{
  ["zhonger_st_heg__zhugeliang"] = "诸葛亮",
  ["#zhonger_st_heg__zhugeliang"] = "迟暮的丞相",
  ["illustrator:zhonger_st_heg__zhugeliang"] = "木美人",
  ["emptycity"] = "空城",
  [":emptycity"] = "锁定技，1.当你成为【杀】或【决斗】的目标时，若你没有手牌，取消之；"..
    "2. 你的回合外，当牌因交给而移至你的手牌区前，你将此次移动的目标区域改为你的武将牌上（均称为“空城”），摸牌阶段开始时，你获得所有“空城”。",
  ["empty"] = "空城",
  ["$emptycity1"] = "（悠扬的琴音）",
  ["$emptycity2"] = "（低沉的琴音）",
  ["~zhonger_st_heg__zhugeliang"] = "将星陨落，天命难违。",
}

local zhaoyun = General(extension, "zhonger_st_heg__zhaoyun", "shu", 4, 4,  General.Male)
zhaoyun:addSkill("hs__longdan")
zhaoyun:addCompanions("zhonger_st_heg__liushan")

Fk:loadTranslationTable{
  ["zhonger_st_heg__zhaoyun"] = "赵云",
  ["#zhonger_st_heg__zhaoyun"] = "虎威将军",
  ["illustrator:zhonger_st_heg__zhaoyun"] = "DH",
  ["~zhonger_st_heg__zhaoyun"] = "你们谁, 还敢再上？",
}

local machao = General(extension, "zhonger_st_heg__machao", "shu", 4, 4,  General.Male)
machao:addSkill("mashu")
machao:addSkill("hs__tieqi")
Fk:loadTranslationTable{
  ["zhonger_st_heg__machao"] = "马超",
  ["#zhonger_st_heg__machao"] = "一骑当千",
  ["illustrator:zhonger_st_heg__machao"] = "KayaK&木美人&张帅",
  ["~zhonger_st_heg__machao"] = "请将我，葬在西凉……",
}

local huangyueying = General(extension, "zhonger_st_heg__huangyueying", "shu", 3, 3, General.Female)
huangyueying:addSkill("jizhi")
huangyueying:addSkill("qicai")
huangyueying:addCompanions("zhonger_st_heg__wolong")

Fk:loadTranslationTable{
  ["zhonger_st_heg__huangyueying"] = "黄月英",
  ["#zhonger_st_heg__huangyueying"] = "归隐的杰女",
  ["illustrator:zhonger_st_heg__huangyueying"] = "木美人",
  ["~zhonger_st_heg__huangyueying"] = "亮……",
}

local huangzhong = General(extension, "zhonger_st_heg__huangzhong", "shu", 4, 4,  General.Male)
local liegong = fk.CreateTriggerSkill{
  name = "hs__firebow",
  anim_type = "offensive",
  events = {fk.TargetSpecified},
  can_trigger = function(self, event, target, player, data)
    if not (target == player and player:hasSkill(self)) then return end
    local room = player.room
    local to = room:getPlayerById(data.to)
    local filter = to.hp >= player.hp
    return data.card.trueName == "slash" and filter 
  end,
  on_use = function(self, event, target, player, data)
    local choices = {"firebow-damage","firebow-qiangzhong"}
    local room = player.room
    local choice = room:askForChoice(player, choices, self.name,"#firebow-chosen")
    if choice == "firebow-damage" then
      data.additionalDamage = (data.additionalDamage or 0) + 1
    else
    data.disresponsiveList = data.disresponsiveList or {}
    table.insert(data.disresponsiveList, data.to)
    end
  end,
}
local liegongAR = fk.CreateAttackRangeSkill{
  name = "#hs__firebowAR",
  correct_func = function(self, from, to)
    if from:hasSkill("hs__firebow") then
      for _, p in ipairs(Fk:currentRoom().alive_players) do
        if string.find(p.general, "lord") and p:hasSkill("shouyue") and p.kingdom == from.kingdom then
          return 1
        end
      end
    end
    return 0
  end,
}
local liegong_t = fk.CreateTargetModSkill{
  name = "#ZE__liegong_targetmod",
    bypass_distances =  function(self, player, skill, card, target)
    if skill.trueName == "slash_skill" and player:hasSkill(liegong) then
      return card and target and target:getHandcardNum() <= player:getHandcardNum() 
      end
  end,
}
liegong:addRelatedSkill(liegongAR)
liegong:addRelatedSkill(liegong_t)
huangzhong:addSkill(liegong)
huangzhong:addCompanions("zhonger_st_heg__weiyan")
Fk:loadTranslationTable{
  ["zhonger_st_heg__huangzhong"] = "黄忠",
  ["#zhonger_st_heg__huangzhong"] = "老当益壮",
  ["illustrator:zhonger_st_heg__huangzhong"] = "匠人绘",
  ["hs__firebow"] = "烈弓",
  [":hs__firebow"] = "你对手牌数小于等于你的角色使用【杀】无距离关系的限制。当你于使用【杀】指定一个目标后，若其体力值大于等于你，你可以选择一项：1.令此【杀】对其造成的伤害+1；2.令其不能使用【闪】响应此【杀】。",
  ["firebow-damage"]="此【杀】的伤害+1",
  ["firebow-qiangzhong"]="此【杀】不可被响应",
  ["#firebow-chosen"]="烈弓：选择一项",
  ["$hs__firebow1"] = "龙骨成镞，矢破苍穹。",
  ["$hs__firebow2"] = "凤翎为羽，箭没坚城。",
  ["~zhonger_st_heg__huangzhong"] = "末将有负主公重托……",
}

local weiyan = General(extension, "zhonger_st_heg__weiyan", "shu", 4, 4,  General.Male)
local kuanggu = fk.CreateTriggerSkill{
  name = "hs__kuanggu",
  anim_type = "drawcard",
  events = {fk.Damage},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and target == player and (data.extra_data or {}).kuanggucheck
  end,
  on_trigger = function(self, event, target, player, data)
    self.cancel_cost = false
    for i = 1, data.damage do
      self:doCost(event, target, player, data)
      if self.cost_data == "Cancel" then break end
    end
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local choices = {"draw1", "Cancel"}
    if player:isWounded() then
      table.insert(choices, 2, "recover")
    end
    self.cost_data = room:askForChoice(player, choices, self.name)
    return self.cost_data ~= "Cancel"
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if self.cost_data == "recover" then
      room:recover({
        who = player,
        num = 1,
        recoverBy = player,
        skillName = self.name
      })
    elseif self.cost_data == "draw1" then
      player:drawCards(1, self.name)
    end
  end,

  refresh_events = {fk.BeforeHpChanged},
  can_refresh = function(self, event, target, player, data)
    return data.damageEvent and player == data.damageEvent.from and player:compareDistance(target, 2, "<")
  end,
  on_refresh = function(self, event, target, player, data)
    data.damageEvent.extra_data = data.damageEvent.extra_data or {}
    data.damageEvent.extra_data.kuanggucheck = true
  end,
}
weiyan:addSkill(kuanggu)

Fk:loadTranslationTable{
  ["zhonger_st_heg__weiyan"] = "魏延",
  ["#zhonger_st_heg__weiyan"] = "嗜血的独狼",
  ["illustrator:zhonger_st_heg__weiyan"] = "瞌瞌一休",

  ["hs__kuanggu"] = "狂骨",
  [":hs__kuanggu"] = "当你对距离1以内的角色造成1点伤害后，你可摸一张牌或回复1点体力。",

  ["$hs__kuanggu1"] = "哈哈哈哈哈哈，赢你还不容易？",
  ["$hs__kuanggu2"] = "哼！也不看看我是何人！",
  ["~zhonger_st_heg__weiyan"] = "奸贼……害我……",
}

local pangtong = General(extension, "zhonger_st_heg__pangtong", "shu",3, 3,  General.Male)
pangtong:addSkill("hs__lianhuan")
pangtong:addSkill("niepan")
pangtong:addCompanions("zhonger_st_heg__wolong")
Fk:loadTranslationTable{
  ['zhonger_st_heg__pangtong'] = '庞统',
  ["#zhonger_st_heg__pangtong"] = "凤雏",
  ["illustrator:zhonger_st_heg__pangtong"] = "KayaK",
  ["~zhonger_st_heg__pangtong"] = "看来我命中注定将丧命于此……",
}

local wolong = General(extension, "zhonger_st_heg__wolong", "shu", 3, 3,  General.Male)
wolong:addSkill("bazhen")
wolong:addSkill("hs__huoji")
wolong:addSkill("hs__kanpo")
Fk:loadTranslationTable{
  ['zhonger_st_heg__wolong'] = '卧龙诸葛亮',
  ["#zhonger_st_heg__wolong"] = "卧龙",
  ["illustrator:zhonger_st_heg__wolong"] = "绘聚艺堂",
  ["~zhonger_st_heg__wolong"] = "我的计谋竟被……",
}

local liushan = General(extension, "zhonger_st_heg__liushan", "shu", 3, 3,  General.Male)
liushan:addSkill("xiangle")
liushan:addSkill("fangquan")
Fk:loadTranslationTable{
  ['zhonger_st_heg__liushan'] = '刘禅',
  ["#zhonger_st_heg__liushan"] = "无为的真命主",
  ["illustrator:zhonger_st_heg__liushan"] = "LiuHeng",
  ["~zhonger_st_heg__liushan"] = "别打脸，我投降还不行吗？",
}

local menghuo = General(extension, "zhonger_st_heg__menghuo", "shu", 4, 4,  General.Male)
menghuo:addCompanions("zhonger_st_heg__zhurong")
local zaiqi = fk.CreateTriggerSkill{
  name = "heg__exzaiqi",
  events = {fk.EventPhaseEnd},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) and player.phase == Player.Discard then
      local ids = {}
      local room = player.room
      local turn_event = room.logic:getCurrentEvent():findParent(GameEvent.Turn)
      if turn_event == nil then return false end
      room.logic:getEventsByRule(GameEvent.MoveCards, 1, function (e)
        for _, move in ipairs(e.data) do
          if move.toArea == Card.DiscardPile then
            for _, info in ipairs(move.moveInfo) do
              table.insertIfNeed(ids, info.cardId)
            end
          end
        end
        return false
      end, turn_event.id)
      local x = #table.filter(ids, function (id)
        return room:getCardArea(id) == Card.DiscardPile and Fk:getCardById(id).suit == Card.Heart   --红桃牌
      end)
      if x > 0 then
        self.cost_data = x
        return true
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local x = self.cost_data
    local targets = table.map(table.filter(room.alive_players, function(p) return H.compareKingdomWith(p, player) end), Util.IdMapper)
    local tos = room:askForChoosePlayers(player, targets, 1, x,
    "#heg__exzaiqi-choose:::"..x, self.name, true)
    if #tos > 0 then
      room:sortPlayersByAction(tos)
      self.cost_data = {tos = tos}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local targets = table.map(self.cost_data.tos, Util.Id2PlayerMapper)
    for _, p in ipairs(targets) do
      if not p.dead then
        local choices = {"heg__exzaiqi_draw"}
        if player and not player.dead and player:isWounded() then
          table.insert(choices, "heg__exzaiqi_recover")
        end
        local choice = room:askForChoice(p, choices, self.name, "#heg__exzaiqi-choice:"..player.id)
        if choice == "heg__exzaiqi_draw" then
          p:drawCards(1, self.name)
        else
          room:recover({
            who = player,
            num = 1,
            recoverBy = p,
            skillName = self.name
          })
        end
      end
    end
  end,
}
local huoshou = fk.CreateTriggerSkill{
  name = "heg__huoshou",
  anim_type = "defensive",
  frequency = Skill.Compulsory,
  events = {fk.PreCardEffect, fk.TargetSpecified},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) and data.card.trueName == "savage_assault" then
      if event == fk.PreCardEffect then
        return player.id == data.to
      else
        return target ~= player and data.firstTarget
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    if event == fk.PreCardEffect then
      return true
    else
      data.extra_data = data.extra_data or {}
      data.extra_data.huoshou = player.id
    end
  end,

  refresh_events = {fk.PreDamage},
  can_refresh = function(self, event, target, player, data)
    if data.card and data.card.trueName == "savage_assault" then
      local e = player.room.logic:getCurrentEvent():findParent(GameEvent.UseCard)
      if e then
        local use = e.data[1]
        return use.extra_data and use.extra_data.huoshou
      end
    end
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    local e = room.logic:getCurrentEvent():findParent(GameEvent.UseCard)
    if e then
      local use = e.data[1]
      data.from = room:getPlayerById(use.extra_data.huoshou)
    end
  end,
}
menghuo:addSkill(huoshou)
menghuo:addSkill(zaiqi)
Fk:loadTranslationTable{
  ['zhonger_st_heg__menghuo'] = '孟获',
  ["#zhonger_st_heg__menghuo"] = "南蛮王",
  ["illustrator:zhonger_st_heg__menghuo"] = "废柴男",

  ["heg__huoshou"] = "祸首",
  [":heg__huoshou"] = "锁定技，【南蛮入侵】对你无效；当其他角色使用【南蛮入侵】指定目标后，你代替其成为此牌造成的伤害的来源。",

  ["heg__exzaiqi"] = "再起",
  [":heg__exzaiqi"] = "弃牌阶段结束时，你可选择至多X名与你势力相同的角色（X为弃牌堆里于此回合内移至此区域的<font color='red'>♥</font>牌数），这些角色各选择：1.令你回复1点体力；2.摸一张牌。",
  ["#heg__exzaiqi-choose"] = "再起：选择至多%arg名与你势力相同的角色，这些角色各选择令你回复1点体力或摸一张牌",

  ["#heg__exzaiqi-choice"] = "再起：选择摸一张牌或令%src回复1点体力",
  ["heg__exzaiqi_draw"] = "摸一张牌",
  ["heg__exzaiqi_recover"] = "令其回复体力",
  
  ["$heg__huoshou1"] = "背黑锅我来，送死？你去！",
  ["$heg__huoshou2"] = "通通算我的！",
  ["$heg__exzaiqi1"] = "丞相助我！",
  ["$heg__exzaiqi2"] = "起！",
  ["~zhonger_st_heg__menghuo"] = "七纵之恩……来世……再报了……",

}

local zhurong = General(extension, "zhonger_st_heg__zhurong", "shu", 4, 4, General.Female)
zhurong:addSkill("juxiang")
zhurong:addSkill("lieren")
Fk:loadTranslationTable{
  ['zhonger_st_heg__zhurong'] = '祝融',
  ["#zhonger_st_heg__zhurong"] = "野性的女王",
  ["illustrator:zhonger_st_heg__zhurong"] = "废柴男",
  ["~zhonger_st_heg__zhurong"] = "大王，我，先走一步了。",

}

local ganfuren = General(extension, "zhonger_st_heg__ganfuren", "shu", 3, 3, General.Female)
local shushen = fk.CreateTriggerSkill{
  name = "zhonger_st_heg__shushen",
  anim_type = "support",
  events = {fk.HpRecover},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self)
  end,
  on_trigger = function(self, event, target, player, data)
    self.cancel_cost = false
    for i = 1, data.num do
      if self.cancel_cost then break end
      self:doCost(event, target, player, data)
    end
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local to = room:askForChoosePlayers(player, table.map(room:getOtherPlayers(player),
    Util.IdMapper), 1, 1, "#heg__shushen-choose", self.name, true)
    if #to > 0 then
      self.cost_data = to[1]
      return true
    end
    self.cancel_cost = true
  end,
  on_use = function(self, event, target, player, data)
    if  player.room:getPlayerById(self.cost_data):isKongcheng() then --如果没有手牌
    player.room:getPlayerById(self.cost_data):drawCards(2, self.name)
  else
    player.room:getPlayerById(self.cost_data):drawCards(1, self.name)
  end
  end,
}

ganfuren:addSkill(shushen)
ganfuren:addSkill("shenzhi")

Fk:loadTranslationTable{
  ['zhonger_st_heg__ganfuren'] = '甘夫人',
  ["#zhonger_st_heg__ganfuren"] = "昭烈皇后",
  ["illustrator:zhonger_st_heg__ganfuren"] = "琛·美弟奇",
  ["designer:zhonger_st_heg__ganfuren"] = "淬毒",

  ["zhonger_st_heg__shushen"] = "淑慎",
  [":zhonger_st_heg__shushen"] = "当你回复1点体力后，你可令一名其他角色摸一张牌,若其没有手牌，则改为摸两张牌。",
  ["#heg__shushen-choose"] = "淑慎：你可令一名其他角色摸一张牌(若其没有手牌，则改为摸两张牌)",
  ["$zhonger_st_heg__shushen1"] = "船到桥头自然直。",
  ["$zhonger_st_heg__shushen2"] = "妾身无恙，相公请安心征战。",
  ["~zhonger_st_heg__ganfuren"] = "请替我照顾好阿斗……",
}

local sunquan = General(extension, "zhonger_st_heg__sunquan", "wu", 4, 4,  General.Male)
sunquan:addSkill("hs__zhiheng")
sunquan:addCompanions("zhonger_st_heg__zhoutai")
Fk:loadTranslationTable{
  ["zhonger_st_heg__sunquan"] = "孙权",
  ["#zhonger_st_heg__sunquan"] = "年轻的贤君",
  ["illustrator:zhonger_st_heg__sunquan"] = "KayaK",
  ["~zhonger_st_heg__sunquan"] = "父亲，大哥，仲谋愧矣……",
}

local ganning = General(extension, "zhonger_st_heg__ganning", "wu", 4, 4,  General.Male)
ganning:addSkill("hs__qixi")
Fk:loadTranslationTable{
  ["zhonger_st_heg__ganning"] = "甘宁",
  ["#zhonger_st_heg__ganning"] = "锦帆游侠",
  ["illustrator:zhonger_st_heg__ganning"] = "KayaK",
  ["~zhonger_st_heg__ganning"] = "二十年后，又是一条好汉！",
}

local lvmeng = General(extension, "zhonger_st_heg__lvmeng", "wu", 4, 4,  General.Male)
lvmeng:addSkill("hs__keji")
lvmeng:addSkill("hs__mouduan")

Fk:loadTranslationTable{
  ["zhonger_st_heg__lvmeng"] = "吕蒙",
  ["#zhonger_st_heg__lvmeng"] = "士别三日",
  ["illustrator:zhonger_st_heg__lvmeng"] = "樱花闪乱",
  ["~zhonger_st_heg__lvmeng"] = "以后，就交给年轻人了。",
}

local huanggai = General(extension, "zhonger_st_heg__huanggai", "wu", 4, 4,  General.Male)
huanggai:addSkill("hs__kurou")
huanggai:addCompanions("zhonger_st_heg__zhouyu")
Fk:loadTranslationTable{
  ["zhonger_st_heg__huanggai"] = "黄盖",
  ["#zhonger_st_heg__huanggai"] = "轻身为国",
  ["illustrator:zhonger_st_heg__huanggai"] = "G.G.G.",
  ["~zhonger_st_heg__huanggai"] = "盖，有负公瑾重托……",
}

local zhouyu = General(extension, "zhonger_st_heg__zhouyu", "wu", 3, 3,  General.Male)
zhouyu:addSkill("ex__yingzi")
zhouyu:addSkill("ex__fanjian")
zhouyu:addCompanions("zhonger_st_heg__xiaoqiao")
Fk:loadTranslationTable{
  ["zhonger_st_heg__zhouyu"] = "周瑜",
  ["#zhonger_st_heg__zhouyu"] = "大都督",
  ["illustrator:zhonger_st_heg__zhouyu"] = "绘聚艺堂",
  ["~zhonger_st_heg__zhouyu"] = "既生瑜，何生亮。既生瑜，何生亮！",
}

local daqiao = General(extension, "zhonger_st_heg__daqiao", "wu", 3, 3, General.Female)
local guose = fk.CreateViewAsSkill{
  name = "hs__guose",
  anim_type = "control",
  pattern = "indulgence",
  expand_pile = "$carriage&",
  card_filter = function(self, to_select, selected)
    if #selected == 1 then return false end
    if Self:getPileNameOfId(to_select)  == "$carriage&" or Fk:getCardById(to_select)  then
    return Fk:getCardById(to_select).suit == Card.Diamond
    end
  end,
  view_as = function(self, cards)
    if #cards ~= 1 then
      return nil
    end
    local c = Fk:cloneCard("indulgence")
    c.skillName = self.name
    c:addSubcard(cards[1])
    return c
  end,
  enabled_at_response = function (self, player, response)
    return not response
  end
}
daqiao:addSkill(guose)
daqiao:addSkill("liuli")
daqiao:addCompanions("zhonger_st_heg__xiaoqiao")

Fk:loadTranslationTable{
  ["zhonger_st_heg__daqiao"] = "大乔",
  ["#zhonger_st_heg__daqiao"] = "矜持之花",
  ["illustrator:zhonger_st_heg__daqiao"] = "KayaK",
  ["$hs__guose1"] = "请休息吧。",
  ["$hs__guose2"] = "你累了。",
  ["hs__guose"] = "国色",
  [":hs__guose"] = "出牌阶段，你可以将一张<font color='red'>♦</font>牌当【乐不思蜀】使用。",
  ["~zhonger_st_heg__daqiao"] = "伯符，我去了……",
}

local luxun = General(extension, "zhonger_st_heg__luxun", "wu", 3, 3,  General.Male)
local duoshi = fk.CreateTriggerSkill{
  name = "stheg_duoshi",
  anim_type = "drawcard",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    local card = Fk:cloneCard("await_exhausted")
    return player:hasSkill(self) and player == target and player.phase == Player.Play and not player:prohibitUse(card)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local targets = table.filter(room.alive_players, function(p) return
      H.compareKingdomWith(p, player) end)
    room:useVirtualCard("await_exhausted", {}, player, targets, self.name)
  end,
}
luxun:addSkill("hs__qianxun")
luxun:addSkill(duoshi)

Fk:loadTranslationTable{
  ["zhonger_st_heg__luxun"] = "陆逊",
  ["#zhonger_st_heg__luxun"] = "擎天之柱",
  ["illustrator:zhonger_st_heg__luxun"] = "KayaK",
  ["stheg_duoshi"] = "度势",
  [":stheg_duoshi"] = "出牌阶段开始时，你可以视为使用一张【以逸待劳】。",
  ["$hs__qianxun_zhonger_st_heg__luxun1"] = "满招损，谦受益。",
  ["$hs__qianxun_zhonger_st_heg__luxun2"] = "谦谦君子，温润如玉。",
  ["$stheg_duoshi1"] = "以今日之大势，当行此计。",
  ["$stheg_duoshi2"] = "国之大计，审势为先。",
  ["~zhonger_st_heg__luxun"] = "我的未竟之业……",
}

local sunshangxiang = General(extension, "zhonger_st_heg__sunshangxiang", "wu", 3, 3, General.Female)
local xiaoji = fk.CreateTriggerSkill{
  name = "zhonger_st_heg__xiaoji",
  anim_type = "drawcard",
  events = {fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(self) then return end
    for _, move in ipairs(data) do
      if move.from == player.id then
        for _, info in ipairs(move.moveInfo) do
          if info.fromArea == Card.PlayerEquip then
            return true
          end
        end
      end
    end
  end,
  on_use = function(self, event, target, player, data)
      player:drawCards(2, self.name)
  end,
}
sunshangxiang:addSkill(xiaoji)
sunshangxiang:addSkill("hs__jieyin")

Fk:loadTranslationTable{
  ["zhonger_st_heg__sunshangxiang"] = "孙尚香",
  ["#zhonger_st_heg__sunshangxiang"] = "弓腰姬",
  ["zhonger_st_heg__xiaoji"] = "枭姬",
  [":zhonger_st_heg__xiaoji"] = "当你失去装备区的装备牌后，你可以摸两张牌。",
  ["$zhonger_st_heg__xiaoji1"] = "哼！",
  ["$zhonger_st_heg__xiaoji2"] = "看我的厉害！",
  ["illustrator:zhonger_st_heg__sunshangxiang"] = "凡果",
  ["~zhonger_st_heg__sunshangxiang"] = "不！还不可以死！",
}

local sunjian = General:new(extension, "zhonger_st_heg__sunjian", "wu", 5)
local yinghun = fk.CreateTriggerSkill{
  name = "hs__yinghun",
  anim_type = "drawcard",
  mute = true,
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.phase == Player.Start
  end,
  on_cost = function(self, event, target, player, data)
    local to = player.room:askForChoosePlayers(player, table.map(player.room:getOtherPlayers(player), function (p)
      return p.id end), 1, 1, "#yinghun-choose:::"..player:getLostHp()..":"..player:getLostHp(), self.name, true)
    if #to > 0 then
      self.cost_data = to[1]
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(self.cost_data)
    local n = player:getLostHp()
    local choice = room:askForChoice(player, {"#yinghun-draw:::" .. n,  "#yinghun-discard:::" .. n}, self.name)
    if choice:startsWith("#yinghun-draw") then
      player:broadcastSkillInvoke(self.name, 1)
      room:notifySkillInvoked(player, self.name, "support")
      to:drawCards(n, self.name)
      room:askForDiscard(to, 1, 1, true, self.name, false)
    else
      player:broadcastSkillInvoke(self.name, 2)
      room:notifySkillInvoked(player, self.name, "control")
      to:drawCards(1, self.name)
      room:askForDiscard(to, n, n, true, self.name, false)
    end
  end,
}
sunjian:addSkill(yinghun)
Fk:loadTranslationTable{
  ['zhonger_st_heg__sunjian'] = '孙坚',
  ["#zhonger_st_heg__sunjian"] = "魂佑江东",
  ["illustrator:zhonger_st_heg__sunjian"] = "LiuHeng",

  ["hs__yinghun"] = "英魂",
  [":hs__yinghun"] = "准备阶段，你可选择一名其他角色并选择一项：1.令其摸X张牌，然后弃置一张牌；2.令其摸一张牌，然后弃置X张牌（X为你已损失的体力值）。",
  ["#yinghun-choose"] = "英魂：你可以令一名其他角色：摸%arg张牌然后弃置一张牌，或摸一张牌然后弃置%arg2张牌",
  ["#yinghun-draw"] = "摸%arg张牌，弃置1张牌",
  ["#yinghun-discard"] = "摸1张牌，弃置%arg张牌",

  ["$hs__yinghun1"] = "以吾魂魄，保佑吾儿之基业。",
  ["$hs__yinghun2"] = "不诛此贼三族，则吾死不瞑目！",
  ["~zhonger_st_heg__sunjian"] = "有埋伏！呃……啊！！",
}

local xiaoqiao = General(extension, "zhonger_st_heg__xiaoqiao", "wu", 3, 3, General.Female)
local tianxiang = fk.CreateTriggerSkill{
  name = "stheg__tianxiang",
  anim_type = "defensive",
  events = {fk.DamageInflicted},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and target == player and (player:getMark("stheg__tianxiang_damage-turn") == 0 or player:getMark("stheg__tianxiang_loseHp-turn") == 0)
  end,
  on_cost = function(self, event, target, player, data)
    local tar, card =  player.room:askForChooseCardAndPlayers(player, table.map(player.room:getOtherPlayers(player), Util.IdMapper), 1, 1, ".|.|heart|hand", "#stheg__tianxiang-choose", self.name, true)
    if #tar > 0 and card then
      self.cost_data = {tar[1], card}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(self.cost_data[1])
    local cid = self.cost_data[2]
    room:throwCard(cid, self.name, player, player)

    if to.dead then return true end
    local choices = {}
    if player:getMark("stheg__tianxiang_loseHp-turn") == 0 then
      table.insert(choices, "stheg__tianxiang_loseHp")
    end
    if data.from and not data.from.dead and player:getMark("stheg__tianxiang_damage-turn") == 0 then
      table.insert(choices, "stheg__tianxiang_damage")
    end
    local choice = room:askForChoice(player, choices, self.name, "#stheg__tianxiang-choice::"..to.id)
    if choice == "stheg__tianxiang_loseHp" then
      room:setPlayerMark(player, "stheg__tianxiang_loseHp-turn", 1)
      room:loseHp(to, 1, self.name)
      if not to.dead and (room:getCardArea(cid) == Card.DrawPile or room:getCardArea(cid) == Card.DiscardPile) then
        room:obtainCard(to, cid, true, fk.ReasonJustMove)
      end
    else
      room:setPlayerMark(player, "stheg__tianxiang_damage-turn", 1)
      room:damage{
        from = data.from,
        to = to,
        damage = 1,
        skillName = self.name,
      }
      if not to.dead then
        to:drawCards(math.min(to:getLostHp(), 5), self.name)
      end
    end
    return true
  end,
}
local hongyan = fk.CreateFilterSkill{
  name = "stheg__hongyan",
  card_filter = function(self, to_select, player)
    return to_select.suit == Card.Spade and player:hasSkill(self)
  end,
  view_as = function(self, to_select)
    return Fk:cloneCard(to_select.name, Card.Heart, to_select.number)
  end,
}

local hongyan_maxcards = fk.CreateMaxCardsSkill{
  name = "#stheg__hongyan_maxcards",
  correct_func = function (self, player)
    if player:hasSkill("stheg__hongyan") and #table.filter(player:getCardIds(Player.Equip), function (id) return Fk:getCardById(id).suit == Card.Heart or Fk:getCardById(id).suit == Card.Spade end) > 0  then
      return 1
    end
  end,
}

xiaoqiao:addSkill(tianxiang)
hongyan:addRelatedSkill(hongyan_maxcards)
xiaoqiao:addSkill(hongyan)
Fk:loadTranslationTable{
  ['zhonger_st_heg__xiaoqiao'] = '小乔',
  ["#zhonger_st_heg__xiaoqiao"] = "矫情之花",
  ["illustrator:zhonger_st_heg__xiaoqiao"] = "绘聚艺堂",

  ["stheg__tianxiang"] = "天香",
  [":stheg__tianxiang"] = "当你受到伤害时，你可弃置一张<font color='red'>♥</font>手牌并选择一名其他角色。你防止此伤害，选择本回合未选择过的一项：1.令来源对其造成1点伤害，其摸X张牌（X为其已损失的体力值且至多为5）；2.令其失去1点体力，其获得牌堆或弃牌堆中你以此法弃置的牌。",
  ["stheg__hongyan"] = "红颜",
  [":stheg__hongyan"] = "锁定技，你的黑桃牌视为红桃牌；若你的装备区内有红桃牌，你的手牌上限+1。",

  ["#stheg__tianxiang-choose"] = "天香：弃置一张<font color='red'>♥</font>手牌并选择一名其他角色",
  ["#stheg__tianxiang-choice"] = "天香：选择一项令 %dest 执行",
  ["stheg__tianxiang_damage"] = "令其受到1点伤害并摸已损失体力值的牌",
  ["stheg__tianxiang_loseHp"] = "令其失去1点体力并获得你弃置的牌",

  ["$stheg__tianxiang1"] = "接着哦~",
  ["$stheg__tianxiang2"] = "替我挡着~",
  ["~zhonger_st_heg__xiaoqiao"] = "公瑾…我先走一步……",
}

local taishici = General(extension, "zhonger_st_heg__taishici", "wu", 4, 4,  General.Male)
taishici:addSkill("tianyi")
Fk:loadTranslationTable{
  ['zhonger_st_heg__taishici'] = '太史慈',
  ["#zhonger_st_heg__taishici"] = "笃烈之士",
  ["illustrator:zhonger_st_heg__taishici"] = "Tuu.",
  ["~zhonger_st_heg__taishici"] = "大丈夫，当带三尺之剑，立不世之功！",
}

local zhoutai = General(extension, "zhonger_st_heg__zhoutai", "wu", 4, 4,  General.Male)
zhoutai:addSkill("hs__buqu")
zhoutai:addSkill("hs__fenji")

Fk:loadTranslationTable{
  ['zhonger_st_heg__zhoutai'] = '周泰',
  ["#zhonger_st_heg__zhoutai"] = "历战之躯",
  ["illustrator:zhonger_st_heg__zhoutai"] = "Thinking",
  ["~zhonger_st_heg__zhoutai"] = "敌众我寡，无力回天……",
}

local lusu = General(extension, "zhonger_st_heg__lusu", "wu", 3, 3,  General.Male)
lusu:addSkill("haoshi")
lusu:addSkill("dimeng")
Fk:loadTranslationTable{
  ['zhonger_st_heg__lusu'] = '鲁肃',
  ["#zhonger_st_heg__lusu"] = "独断的外交家",
  ["illustrator:zhonger_st_heg__lusu"] = "LiuHeng",
  ["~zhonger_st_heg__lusu"] = "此联盟已破，吴蜀休矣。",
}

local erzhang = General(extension, "zhonger_st_heg__zhangzhaozhanghong", "wu", 3, 3,  General.Male)
erzhang:addSkill("zhijian")
erzhang:addSkill("guzheng")
Fk:loadTranslationTable{
  ['zhonger_st_heg__zhangzhaozhanghong'] = '张昭张纮',
  ["#zhonger_st_heg__zhangzhaozhanghong"] = "经天纬地",
  ["illustrator:zhonger_st_heg__zhangzhaozhanghong"] = "废柴男",
  ["~zhonger_st_heg__zhangzhaozhanghong"] = "竭力尽智，死而无憾。",
}

local dingfeng = General(extension, "zhonger_st_heg__dingfeng", "wu", 4, 4,  General.Male)
dingfeng:addSkill("duanbing")
dingfeng:addSkill("fenxun")
Fk:loadTranslationTable{
  ["zhonger_st_heg__dingfeng"] = "丁奉",
  ["#zhonger_st_heg__dingfeng"] = "清侧重臣",
  ["illustrator:zhonger_st_heg__dingfeng"] = "魔鬼鱼",

  ["$duanbing1"] = "众将官，短刀出鞘。",
  ["$duanbing2"] = "短兵轻甲也可取汝性命！",
  ["$fenxun1"] = "取封侯爵赏，正在今日！",
  ["$fenxun2"] = "给我拉过来！",
  ["~zhonger_st_heg__dingfeng"] = "这风，太冷了……",
}
local zhangjiao = General(extension, "zhonger_st_heg__zhangjiao", 'qun', 3, 3,  General.Male)
local leiji = fk.CreateTriggerSkill{
  name = "ze__leiji",
  anim_type = "offensive",
  events = {fk.CardUsing, fk.CardResponding},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and target == player and data.card.name == "jink"
  end,
  on_cost = function(self, event, target, player, data)
    local to = player.room:askForChoosePlayers(player, table.map(player.room:getOtherPlayers(player), function (p)
      return p.id end), 1, 1, "#zeleiji-choose", self.name, true)
    if #to > 0 then
      self.cost_data = to[1]
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local tar = room:getPlayerById(self.cost_data)
    local judge = {
      who = tar,
      reason = self.name,
      pattern = ".|.|spade",
    }
    room:judge(judge)
    if judge.card.suit == Card.Spade then
      room:damage{
        from = player,
        to = tar,
        damage = 2,
        damageType = fk.ThunderDamage,
        skillName = self.name,
      }
    end
end,
}
local guidao = fk.CreateTriggerSkill{
  name = "ze__guidao",
  anim_type = "control",
  events = {fk.AskForRetrial},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and not player:isNude()
  end,
  on_cost = function(self, event, target, player, data)
    local card = player.room:askForCard(player, 1,1,true,self.name,true, ".|.|spade,club|hand,equip", "#zeguidao-ask::" .. target.id .. ":" .. data.reason)
    if #card > 0 then
      self.cost_data = card[1]
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    player.room:retrial(Fk:getCardById(self.cost_data), player, data, self.name, true)
  end,
}
zhangjiao:addSkill(leiji)
zhangjiao:addSkill(guidao)
Fk:loadTranslationTable{
  ['zhonger_st_heg__zhangjiao'] = '张角',
  ["#zhonger_st_heg__zhangjiao"] = "天公将军",
  ["illustrator:zhonger_st_heg__zhangjiao"] = "LiuHeng",

  ["ze__leiji"] = "雷击",
  [":ze__leiji"] = "当你使用或打出【闪】时，你可以令一名角色进行判定，若结果为♠，你对其造成2点雷电伤害。",
  ["ze__guidao"] = "鬼道",
  [":ze__guidao"] = "当一名角色的判定牌生效前，你可以打出一张黑色牌替换之。",
  ["#zeleiji-choose"] = "雷击：你可以令一名角色进行判定，若为♠，你对其造成2点雷电伤害。",
  ["#zeguidao-ask"] = "鬼道：你可以打出一张黑色牌替换 %dest 的 “%arg” 判定",

  ["$ze__leiji1"] = "以我之真气，合天地之造化！",
  ["$ze__leiji2"] = "雷公助我！",
  ["$ze__guidao1"] = "天下大势，为我所控。",
  ['$ze__guidao2'] = "哼哼哼哼~",
  ["~zhonger_st_heg__zhangjiao"] = "黄天…也死了……",
}

local huatuo = General(extension, "zhonger_st_heg__huatuo", "qun", 3, 3,  General.Male)
huatuo:addSkill("hs__jijiu")
huatuo:addSkill("hs__chuli")

Fk:loadTranslationTable{
  ["zhonger_st_heg__huatuo"] = "华佗",
  ["#zhonger_st_heg__huatuo"] = "神医",
  ["illustrator:zhonger_st_heg__huatuo"] = "琛·美弟奇",
  ["~zhonger_st_heg__huatuo"] = "生老病死，命不可违。",
}

local lvbu = General(extension, "zhonger_st_heg__lvbu", "qun", 5)
local wushuang = fk.CreateTriggerSkill{
  name = "spwuu",
  anim_type = "offensive",
  frequency = Skill.Compulsory,
  events = {fk.TargetSpecified, fk.TargetConfirmed,fk.AfterCardTargetDeclared},
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(self) then
      return false
    end
    if event == fk.TargetSpecified then
      return target == player and table.contains({ "slash", "duel" }, data.card.trueName)
    elseif event ==  fk.TargetConfirmed then
      return data.to == player.id and data.card.trueName == "duel"
    elseif event == fk.AfterCardTargetDeclared and data.card.trueName == "duel" and target == player and (not data.card:isVirtual() or #data.card.subcards == 0) then
      local current_targets = TargetGroup:getRealTargets(data.tos)
      for _, p in ipairs(player.room.alive_players) do
        if not table.contains(current_targets, p.id) and not player:isProhibited(p, data.card)  and
            data.card.skill:modTargetFilter(p.id, current_targets, data.from, data.card, true) then
          return true
        end
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    if event == fk.AfterCardTargetDeclared then
      local current_targets = TargetGroup:getRealTargets(data.tos)
      local targets = {}
      for _, p in ipairs(room.alive_players) do
        if not table.contains(current_targets, p.id) and not player:isProhibited(p, data.card) and
            data.card.skill:modTargetFilter(p.id, current_targets, data.from, data.card, true) then
          table.insert(targets, p.id)
        end
      end
      local tos = room:askForChoosePlayers(player, targets, 1, 2,
      "#spwuu-choose:::"..data.card:toLogString(), self.name, true)
      if #tos > 0 then
        self.cost_data = tos
        return true
      end
    else
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    if event == fk.AfterCardTargetDeclared then
      table.insertTable(data.tos, table.map(self.cost_data, function (p)
        return {p}
      end))
    else
      data.fixedResponseTimes = data.fixedResponseTimes or {}
      if data.card.trueName == "slash" then
        data.fixedResponseTimes["jink"] = 2
      else
        data.fixedResponseTimes["slash"] = 2
        data.fixedAddTimesResponsors = data.fixedAddTimesResponsors or {}
        table.insert(data.fixedAddTimesResponsors, (event == fk.TargetSpecified and data.to or data.from))
      end
    end
  end,
}
lvbu:addSkill(wushuang)
lvbu:addCompanions("zhonger_st_heg__diaochan")
Fk:loadTranslationTable{
  ["zhonger_st_heg__lvbu"] = "吕布",
  ["#zhonger_st_heg__lvbu"] = "戟指中原",
  ["illustrator:zhonger_st_heg__lvbu"] = "凡果",
  ["spwuu"] = "无双",
  [":spwuu"] = "锁定技，<br>①你使用的【杀】需要连续使用俩张【闪】才能抵消，与你进行【决斗】的角色每次需要连续打出俩张【杀】。<br>②当你使用非转化的【决斗】后，你可额外选择至多两名其他角色也成为目标。",
  ["#spwuu-choose"] = "无双：你可以为 %arg 增加至多两个目标",
  ["$spwuu1"] = "还有哪个敢挑战我！？",
  ["$spwuu2"] = "三个齐上，也不是我的对手！",
  ["~zhonger_st_heg__lvbu"] = "我竟然输了？不可能！",
}

local diaochan = General(extension, "zhonger_st_heg__diaochan", "qun", 3, 3, General.Female)
diaochan:addSkill("hs__lijian")
diaochan:addSkill("biyue")

Fk:loadTranslationTable{
  ["zhonger_st_heg__diaochan"] = "貂蝉",
  ["#zhonger_st_heg__diaochan"] = "绝世的舞姬",
  ["illustrator:zhonger_st_heg__diaochan"] = "LiuHeng",
  ["~zhonger_st_heg__diaochan"] = "父亲大人，对不起……",
}

local yuanshao = General(extension, "zhonger_st_heg__yuanshao", "qun", 4, 4,  General.Male)
yuanshao:addSkill("hs__luanji")
yuanshao:addCompanions("zhonger_st_heg__yanliangwenchou")

Fk:loadTranslationTable{
  ["zhonger_st_heg__yuanshao"] = "袁绍",
  ["#zhonger_st_heg__yuanshao"] = "高贵的名门",
  ["illustrator:zhonger_st_heg__yuanshao"] = "北辰菌",
  ["~zhonger_st_heg__yuanshao"] = "老天不助我袁家啊！",
}

local sx = General(extension, 'zhonger_st_heg__yanliangwenchou', 'qun', 4, 4,  General.Male)
sx:addSkill('hs__shuangxiong')
Fk:loadTranslationTable{
  ['zhonger_st_heg__yanliangwenchou'] = '颜良文丑',
  ["#zhonger_st_heg__yanliangwenchou"] = "虎狼兄弟",
  ["illustrator:zhonger_st_heg__yanliangwenchou"] = "KayaK",

  ["~zhonger_st_heg__yanliangwenchou"] = "这红脸长须大将是……",
}

local jiaxu = General(extension, 'zhonger_st_heg__jiaxu', 'qun', 3, 3,  General.Male)
jiaxu:addSkill('wansha')
local weimu = fk.CreateTriggerSkill{
  name = "zhonger_st_heg__weimu",
  anim_type = "defensive",
  events = { fk.TargetConfirming, fk.BeforeCardsMove },
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(self) then return false end
    if event == fk.TargetConfirming then
      return target == player and data.card.color == Card.Black and data.card:isCommonTrick()
    elseif event == fk.BeforeCardsMove then
      local id = 0
      local source = player
      local room = player.room
      local c
      for _, move in ipairs(data) do
        if move.to == player.id and move.toArea == Card.PlayerJudge then
          for _, info in ipairs(move.moveInfo) do
            id = info.cardId
            if info.fromArea == Card.PlayerJudge then
              source = room:getPlayerById(move.from) or player
            else
              source = player
            end
            c = source:getVirualEquip(id)
            --FIXME：巨大隐患，延时锦囊的virtual_equips在置入判定区的事件被篡改，或者判定阶段自然流程以外的方式离开判定区时不会清理
            if not c then c = Fk:getCardById(id) end
            if c.sub_type == Card.SubtypeDelayedTrick and c.color == Card.Black then
              return true
            end
          end
        end
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.TargetConfirming then
      AimGroup:cancelTarget(data, player.id)
      return true
    elseif event == fk.BeforeCardsMove then
      local source = player
      local mirror_moves = {}
      local ids = {}
      for _, move in ipairs(data) do
        if move.to == player.id and move.toArea == Card.PlayerJudge then
          local move_info = {}
          local mirror_info = {}
          for _, info in ipairs(move.moveInfo) do
            local id = info.cardId
            if info.fromArea == Card.PlayerJudge then
              source = room:getPlayerById(move.from) or player
            else
              source = player
            end
            local c = source:getVirualEquip(id)
            if not c then c = Fk:getCardById(id) end
            if c.sub_type == Card.SubtypeDelayedTrick and c.color == Card.Black then
              table.insert(mirror_info, info)
              table.insert(ids, id)
            else
              table.insert(move_info, info)
            end
          end
          if #mirror_info > 0 then
            move.moveInfo = move_info
            local mirror_move = table.clone(move)
            mirror_move.to = nil
            mirror_move.toArea = Card.DiscardPile
            mirror_move.moveInfo = mirror_info
            table.insert(mirror_moves, mirror_move)
          end
        end
      end
      table.insertTable(data, mirror_moves)
    end
  end
}

local luanwu = fk.CreateActiveSkill{
  name = "ze_st_heg__luanwu",
  anim_type = "offensive",
  card_num = 0,
  target_num = 0,
  frequency = Skill.Limited,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryGame) == 0
  end,
  card_filter = Util.FalseFunc,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local targets = room:getOtherPlayers(player)
    room:doIndicate(player.id, table.map(targets, Util.IdMapper))
    for _, target in ipairs(targets) do
      if not target.dead then
        local other_players = table.filter(room:getOtherPlayers(target, false), function(p) return not p:isRemoved() end)
        local luanwu_targets = table.map(table.filter(other_players, function(p2)
          return table.every(other_players, function(p1)
            return target:distanceTo(p1) >= target:distanceTo(p2)
          end)
        end), Util.IdMapper)
        local use = room:askForUseCard(target, "slash", "slash", "#ze_st_heg__luanwu-use", true, {exclusive_targets = luanwu_targets, bypass_times = true})
        if use then
          use.extraUse = true
          room:useCard(use)
        else
          room:loseHp(target, 1, self.name)
        end
      end
    end
  end,
}
jiaxu:addSkill(luanwu)
jiaxu:addSkill(weimu)
Fk:loadTranslationTable{
  ['zhonger_st_heg__jiaxu'] = '贾诩',
  ["#zhonger_st_heg__jiaxu"] = "冷酷的毒士",
  ["illustrator:zhonger_st_heg__jiaxu"] = "绘聚艺堂",

  ['zhonger_st_heg__weimu'] = '帷幕',
  [':zhonger_st_heg__weimu'] = '锁定技，当你成为黑色锦囊牌的目标时，取消之。',

  ["ze_st_heg__luanwu"] = "乱武",
  [":ze_st_heg__luanwu"] = "限定技，出牌阶段，你可选择所有其他角色，这些角色各需对包括距离最小的另一名角色在内的角色使用【杀】，否则失去1点体力。",
  ["#ze_st_heg__luanwu-use"] = "乱武：你需要对距离最近的一名角色使用一张【杀】，否则失去1点体力",

  ["$zhonger_st_heg__weimu1"] = "此计伤不到我。",
  ["$zhonger_st_heg__weimu2"] = "你奈我何！",
  ["$ze_st_heg__luanwu1"] = "哼哼哼……坐山观虎斗！",
  ["$ze_st_heg__luanwu2"] = "哭喊吧，哀求吧，挣扎吧，然后，死吧！",
  ["~zhonger_st_heg__jiaxu"] = "我的时辰也到了……",
}

local pangde = General(extension, "zhonger_st_heg__pangde", "qun", 4, 4,  General.Male)
pangde:addSkill("mashu")
pangde:addSkill("jianchu")

Fk:loadTranslationTable{
  ["zhonger_st_heg__pangde"] = "庞德",
  ["#zhonger_st_heg__pangde"] = "人马一体",
  ["illustrator:zhonger_st_heg__pangde"] = "凝聚永恒",
  ["$jianchu1"] = "你，可敢挡我！",
  ["$jianchu2"] = "我要杀你们个片甲不留！",
  ["~zhonger_st_heg__pangde"] = "四面都是水……我命休矣。",
}



local caiwenji = General(extension, "zhonger_st_heg__caiwenji", "qun", 3, 3, General.Female)
caiwenji:addSkill("beige")
caiwenji:addSkill("hs__duanchang")
Fk:loadTranslationTable{
  ["zhonger_st_heg__caiwenji"] = "蔡文姬",
  ["#zhonger_st_heg__caiwenji"] = "异乡的孤女",
  ["illustrator:zhonger_st_heg__caiwenji"] = "SoniaTang",
  ["~zhonger_st_heg__caiwenji"] = "人生几何时，怀忧终年岁。",
}

local mateng = General(extension, "zhonger_st_heg__mateng", "qun", 4, 4,  General.Male)
mateng:addSkill("heg_mateng__mashu")
mateng:addSkill("xiongyi")

Fk:loadTranslationTable{
  ["zhonger_st_heg__mateng"] = "马腾",
  ["#zhonger_st_heg__mateng"] = "驰骋西陲",
  ["desinger:zhonger_st_heg__mateng"] = "淬毒",
  ["illustrator:zhonger_st_heg__mateng"] = "DH",
  ["~zhonger_st_heg__mateng"] = "儿子，为爹报仇啊！",
}

local kongrong = General(extension, "zhonger_st_heg__kongrong", "qun", 3, 3,  General.Male)
kongrong:addSkill("mingshi")
kongrong:addSkill("lirang")
Fk:loadTranslationTable{
  ["zhonger_st_heg__kongrong"] = "孔融",
  ["#zhonger_st_heg__kongrong"] = "凛然重义",
  ["desinger:zhonger_st_heg__kongrong"] = "淬毒",
  ["illustrator:zhonger_st_heg__kongrong"] = "苍月白龙",
  ["~zhonger_st_heg__kongrong"] = "覆巢之下，岂有完卵……",
}

local jiling = General(extension, "zhonger_st_heg__jiling", "qun", 4, 4,  General.Male)
local shuangren = fk.CreateTriggerSkill{
  name = "hs__shuangren",
  anim_type = "offensive",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and player.phase == Player.Play and not player:isKongcheng() and table.find(player.room:getOtherPlayers(player), function(p)
      return not p:isKongcheng()
    end)
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local availableTargets = table.map(
      table.filter(room:getOtherPlayers(player), function(p)
        return not p:isKongcheng()
      end),
      Util.IdMapper
    )
    if #availableTargets == 0 then return false end
    local target = room:askForChoosePlayers(player, availableTargets, 1, 1, "#hs_shuangren-ask", self.name, true)
    if #target > 0 then
      self.cost_data = target[1]
      return true
    end
    return false
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local target = room:getPlayerById(self.cost_data)
    local pindian = player:pindian({target}, self.name)
    if pindian.results[target.id].winner == player then
      if player.dead then return end
      local slash = Fk:cloneCard("slash")
      if player:prohibitUse(slash) then return false end
      local availableTargets = table.map(
        table.filter(room:getOtherPlayers(player), function(p)
          return H.compareKingdomWith(p, target) and not player:isProhibited(p, slash)
        end),
        Util.IdMapper
      )
      if #availableTargets == 0 then return false end
      local victims = room:askForChoosePlayers(player, availableTargets, 1, 1, "#hs_shuangren_slash-ask:" .. target.id, self.name, false)
      if #victims > 0 then
        local to = room:getPlayerById(victims[1])
        if to.dead then return false end
        room:useVirtualCard("slash", nil, player, {to}, self.name, true)
      end
    else
      room:setPlayerMark(player, "hs_shuangren-turn", 1)
    end
  end,
}

local shuangren_prohibit = fk.CreateProhibitSkill{
  name = "#hs__shuangren_prohibit",
  is_prohibited = function(self, from, to, card)
    if from:hasSkill(self) then
      return from:getMark("hs_shuangren-turn") > 0 and from ~= to
    end
  end,
}

shuangren:addRelatedSkill(shuangren_prohibit)
jiling:addSkill(shuangren)
Fk:loadTranslationTable{
  ["zhonger_st_heg__jiling"] = "纪灵",
  ["#zhonger_st_heg__jiling"] = "仲家的主将",
  ["illustrator:zhonger_st_heg__jiling"] = "樱花闪乱",
  ["desinger:zhonger_st_heg__jiling"] = "淬毒",

  
  ["hs__shuangren"] = "双刃",
  [":hs__shuangren"] = "出牌阶段开始时，你可与一名角色拼点。若你：赢，你视为对与其势力相同的一名角色使用【杀】；没赢，其他角色于此回合内不是你使用牌的合法目标。",

  ["#hs_shuangren-ask"] = "双刃：你可与一名角色拼点",
  ["#hs_shuangren_slash-ask"] = "双刃：你视为对与 %src 势力相同的一名角色使用【杀】",

  ["$hs__shuangren1"] = "仲国大将纪灵在此！",
  ["$hs__shuangren2"] = "吃我一记三尖两刃刀！",
  ["~zhonger_st_heg__jiling"] = "额，将军为何咆哮不断……",
}

local tianfeng = General(extension, "zhonger_st_heg__tianfeng", "qun", 3, 3,  General.Male)
tianfeng:addSkill("sijian")
tianfeng:addSkill("suishi")

Fk:loadTranslationTable{
  ["zhonger_st_heg__tianfeng"] = "田丰",
  ["#zhonger_st_heg__tianfeng"] = "河北瑰杰",
  ["illustrator:zhonger_st_heg__tianfeng"] = "地狱许",
  ["desinger:zhonger_st_heg__tianfeng"] = "淬毒",
  ["~zhonger_st_heg__tianfeng"] = "不纳吾言而反诛吾心，奈何奈何！！",
}

local panfeng = General(extension, "zhonger_st_heg__panfeng", "qun", 4, 4,  General.Male)
local kuangfu = fk.CreateTriggerSkill{
  name = "ze_heg__kuangfu",
  events = {fk.TargetSpecified},
  can_trigger = function (self, event, target, player, data)
    if player:hasSkill(self) and data.card and data.card.trueName == "slash" and player.phase == Player.Play and player:usedSkillTimes(self.name, Player.HistoryPhase) == 0 and 
      target == player then
      for _, p in ipairs(AimGroup:getAllTargets(data.tos)) do
        if #player.room:getPlayerById(p):getCardIds(Player.Equip) > 0 then
          return true
        end
      end
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local choice = {}
    for _ , choicePlayers in ipairs(AimGroup:getAllTargets(data.tos)) do
      if #room:getPlayerById(choicePlayers):getCardIds("e") > 0 then
        table.insert(choice, choicePlayers)
      end
    end
    local p = room:askForChoosePlayers(player, choice, 1, 1, "#ze__kuangfu-choice", self.name, true)
    if #p == 0 then return end
    local card = room:askForCardChosen(player, room:getPlayerById(p[1]), "e", self.name)
    room:moveCardTo(card, Card.PlayerHand, player, fk.ReasonPrey, self.name, nil, false, player.id)
    data.extra_data = data.extra_data or {}
    data.extra_data.hs__kuangfuUser = player.id
  end,
}

local kuangfu_delay = fk.CreateTriggerSkill{
  name = "#ze_heg__kuangfu_delay",
  frequency = Skill.Compulsory,
  events = {fk.CardUseFinished},
  can_trigger = function (self, event, target, player, data)
    return (data.extra_data or {}).hs__kuangfuUser == player.id and not data.damageDealt
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    local room = player.room
    room:askForDiscard(player, 2, 2, true, self.name, false)
  end,
}

kuangfu:addRelatedSkill(kuangfu_delay)
panfeng:addSkill(kuangfu)
Fk:loadTranslationTable{
  ["zhonger_st_heg__panfeng"] = "潘凤",
  ["#zhonger_st_heg__panfeng"] = "联军上将",
  ["illustrator:zhonger_st_heg__panfeng"] = "凡果",
  
  ["ze_heg__kuangfu"] = "狂斧",
  [":ze_heg__kuangfu"] = "出牌阶段限一次，当你使用【杀】指定目标后，你可获得此牌其中一个目标角色装备区内的一张牌，然后此牌结算后，若此牌未造成过伤害，你弃置两张牌。",

  ["#ze_heg__kuangfu_delay"] = "狂斧",
  ["#ze__kuangfu-choice"] = "狂斧：选择一名装备区内有牌且是此牌目标的角色，获得其装备区内一张牌",
  ["$ze_heg__kuangfu1"] = "大斧到处，片甲不留！",
  ["$ze_heg__kuangfu2"] = "你可接得住我一斧？",
  ["~zhonger_st_heg__panfeng"] = "潘凤又被华雄斩啦。",
}


local zoushi = General(extension, "zhonger_st_heg__zoushi", "qun", 3, 3, General.Female)
local huoshui = fk.CreateTriggerSkill{ -- FIXME
  name = "ze_st_heg_huoshui",
  anim_type = "control",
  frequency = Skill.Compulsory,
  events = {fk.TurnStart, fk.GeneralRevealed, fk.EventAcquireSkill, fk.EventLoseSkill, fk.Deathed, fk.CardUsing},
  can_trigger = function(self, event, target, player, data)
    if target ~= player or player.room.current ~= player then return false end
    if event == fk.TurnStart then
      return player:hasShownSkill(self)
    end
    if event == fk.EventAcquireSkill or event == fk.EventLoseSkill then
      return data == self
    elseif event == fk.GeneralRevealed then
      if player:hasSkill(self) then
        for _, v in pairs(data) do
          if table.contains(Fk.generals[v]:getSkillNameList(), self.name) then return true end
        end
      end
    elseif event == fk.CardUsing then
      return player:hasSkill(self)  and (data.card.trueName == "slash" or data.card.trueName == "archery_attack")
    else
      return player:hasSkill(self, true, true)
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if table.contains({fk.TurnStart, fk.GeneralRevealed, fk.EventAcquireSkill}, event) then
      local targets = {}
      for _, p in ipairs(room:getOtherPlayers(player)) do
        room:setPlayerMark(p, "@@zehuoshui-turn", 1)
        local record = p:getTableMark(MarkEnum.RevealProhibited .. "-turn")
        table.insertTable(record, {"m", "d"})
        room:setPlayerMark(p, MarkEnum.RevealProhibited .. "-turn", record)
        table.insert(targets, p.id)
      end
      room:doIndicate(player.id, targets)
    elseif event == fk.CardUsing then
      local targets = table.filter(room.alive_players, function(p) return (not H.compareKingdomWith(p, player)) and H.getGeneralsRevealedNum(p) == 1 end)
      if #targets > 0 then
        data.disresponsiveList = data.disresponsiveList or {}
        for _, p in ipairs(targets) do
          table.insertIfNeed(data.disresponsiveList, p.id)
        end
      end
    else
      for _, p in ipairs(room:getOtherPlayers(player)) do
        room:setPlayerMark(p, "@@zehuoshui-turn", 0)
        local record = p:getTableMark(MarkEnum.RevealProhibited .. "-turn")
        table.removeOne(record, "m")
        table.removeOne(record, "d")
        if #record == 0 then record = 0 end
        room:setPlayerMark(p, MarkEnum.RevealProhibited .. "-turn", record)
      end
    end
  end,
}
local qingcheng = fk.CreateActiveSkill{
  name = "ze_st_heg_qingcheng",
  anim_type = "control",
  card_num = 1,
  target_num = 1,
  card_filter = function(self, to_select, selected, targets)
    return #selected == 0 and Fk:getCardById(to_select).color == Card.Black
  end,
  target_filter = function(self, to_select, selected, selected_cards)
    if #selected > 0 or #selected_cards == 0 then return false end --TODO
    local target = Fk:currentRoom():getPlayerById(to_select)
    return to_select ~= Self.id and target.general ~= "anjiang" and target.deputyGeneral ~= "anjiang"
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    local ret = false
    if Fk:getCardById(effect.cards[1]).type == Card.TypeEquip then
      ret = true
    end
    room:throwCard(effect.cards, self.name, player, player)
    H.doHideGeneral(room, player, target, self.name)
    if ret and not player.dead then
      local targets = table.filter(room.alive_players, function(p) return p.general ~= "anjiang" and p.deputyGeneral ~= "anjiang" and p ~= player and p ~= target end)
      if #targets == 0 then return false end
      local to = room:askForChoosePlayers(player, table.map(targets, Util.IdMapper), 1, 1, "#heg_qingcheng-again", self.name, true)
      if #to > 0 then
        target = room:getPlayerById(to[1])
        H.doHideGeneral(room, player, target, self.name)
      end
    end
  end,
}
zoushi:addSkill(huoshui)
zoushi:addSkill(qingcheng)
Fk:loadTranslationTable{
  ["zhonger_st_heg__zoushi"] = "邹氏",
  ["ze_st_heg_huoshui"] = "祸水",
  [":ze_st_heg_huoshui"] = "锁定技，你的回合内：1.其他角色不能明置其武将牌；2.当你使用【杀】或【万箭齐发】指定目标后，你令此牌不能被与你势力不同且有暗置武将牌的角色响应。",
  ["ze_st_heg_qingcheng"] = "倾城",
  [":ze_st_heg_qingcheng"] = "出牌阶段，你可弃置一张黑色牌并选择一名武将牌均明置的其他角色，然后你暗置其一张武将牌。然后若你以此法弃置的牌是黑色装备牌，则你可再选择另一名武将牌均明置的其他角色，暗置其一张武将牌。",

  ["@@zehuoshui-turn"] = "祸水",
  ["#heg_qingcheng-again"] = "倾城：你可再选择另一名武将牌均明置的其他角色，暗置其一张武将牌",

  ["$ze_st_heg_huoshui1"] = "走不动了嘛？" ,
  ["$ze_st_heg_huoshui2"] = "别走了在玩一会嘛？" ,
  ["$ze_st_heg_qingcheng1"] = "我和你们真是投缘啊。",
  ["$ze_st_heg_qingcheng2"] = "哼，眼睛都直了呀。",
  ["~zhonger_st_heg__zoushi"] = "年老色衰了吗？",
}

return {card_extension, extension}